package com.init.iblog.controller;

import com.init.iblog.annotation.SystemLog;
import com.init.iblog.domain.ResponseResult;
import com.init.iblog.domain.entity.User;
import com.init.iblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询个人信息
     * @return
     */
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){
        System.out.println("++++++++++++++++进入/userInfo查询用户个人信息接口++++++++++++++++");
        return userService.userInfo();
    }


    /**
     * 更新用户个人信息
     * @param user
     * @return
     */
    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    public ResponseResult updateUserInfo(@RequestBody User user){

        System.out.println("+++++++++++进入/userInfo接口");

        System.out.println("==========前端传来的参数user="+user);
        return userService.updateUserInfo(user);
    }


    /**
     * 用户注册
     * @return
     */
    @PostMapping("/register")
    public ResponseResult register(@RequestBody  User user){

        System.out.println("===================进入/register接口");
        System.out.println("++++++++++++++++++前端传来的参数user = "+user);
        return userService.register(user);
    }
}
